--[[
* MapNotes 2.0
* File: MapNotes\MapNotes_Tooltip.lua
* $Revision: 132 $
* $Date: 2007-01-06 13:08:56 +0000 (Sat, 06 Jan 2007) $
* 
* Copyright (c) 2006-2007, Mery (Moritz Metelmann)
* All rights reserved.
* 
* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
* 
*    * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
*    * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
*    * Neither the name of the <ORGANIZATION> nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
]]--

if (not MapNotes) then MapNotes = {}; end;
if (not MapNotes.XML) then MapNotes.XML = {}; end;
if (not MapNotes.Tooltip) then MapNotes.Tooltip = {}; end;

MapNotes.XML.CreateTooltip = function()
	--Create POI Tooltip
	local fr = CreateFrame("Frame", "MapNotesPOITooltip", MapLibFrame);
	fr:Hide();
	fr:SetFrameStrata("TOOLTIP");
	fr:SetBackdrop({
		bgFile = "Interface\\Tooltips\\UI-Tooltip-Background", 
		edgeFile = "Interface\\Tooltips\\UI-Tooltip-Border", tile = true, tileSize = 16, edgeSize = 16, 
		insets = { left = 5, right = 5, top = 5, bottom = 5 }
	});
	fr:SetBackdropBorderColor(MapLib.colors[3].r, MapLib.colors[3].g, MapLib.colors[3].b);
	fr:SetBackdropColor(MapLib.colors[4].r, MapLib.colors[4].g, MapLib.colors[4].b);
	fr:SetWidth(160);
	fr:SetHeight(41); -- 25 = one line, 41 = 2 lines
	fr:SetPoint("CENTER", MapLibButton, "CENTER", 0, 0);
	fr:SetFrameLevel(MapLib.FRAMELEVEL_MENU_AND_TOOLTIP);
	
	local texture = fr:CreateTexture("MapNotesPOITooltipBG", "ARTWORK");
	texture:SetHeight(16);
	texture:SetWidth(150);
	texture:SetTexture(MapLib.PATH.."\\Artwork\\BG");
	texture:SetPoint("TOP", MapNotesPOITooltip, "TOP", 0, -5);
	texture:SetVertexColor(MapLib.colors[1].r, MapLib.colors[1].g, MapLib.colors[1].b);
	
	texture = fr:CreateTexture("MapNotesPOITooltipIcon", "OVERLAY");
	texture:SetHeight(14);
	texture:SetWidth(14);
	texture:SetPoint("LEFT", MapNotesPOITooltipBG, "LEFT", 2, 0);
	
	local fontstring = fr:CreateFontString("MapNotesPOITooltipHeader", "OVERLAY", "GameFontHighlightSmall");
	fontstring:SetText("Moritz");
	fontstring:SetJustifyH("LEFT");
	fontstring:SetHeight(16);
	fontstring:SetWidth(189);
	fontstring:SetPoint("LEFT", MapNotesPOITooltipIcon, "RIGHT", 0, 1);
	fontstring = fr:CreateFontString("MapNotesPOITooltipDescription", "OVERLAY", "GameFontHighlightSmall");
	fontstring:SetText("Description");
	fontstring:SetJustifyH("LEFT");
	fontstring:SetWidth(209);
	fontstring:SetPoint("TOPLEFT", MapNotesPOITooltipBG, "BOTTOMLEFT", 0, -1);	
end;

MapNotes.XML.CreateTooltip();
MapNotes.XML.CreateTooltip = nil;

MapNotes.Tooltip.BuildTooltip = function(noteID)
	-- If NOT noteID then return and not found tooltip!
	-- set icon
	local texture = MapNotes.Icon.GetIconTexture(MapNotesSaved_NoteDB[noteID].iconID, MapNotesSaved_NoteDB[noteID].category);
	MapNotesPOITooltipIcon:SetTexture(texture.file);
	if (texture.tcoordMinX) then MapNotesPOITooltipIcon:SetTexCoord(texture.tcoordMinX, texture.tcoordMaxX, texture.tcoordMinY, texture.tcoordMaxY); else MapNotesPOITooltipIcon:SetTexCoord(0, 1, 0, 1); end;
	if (texture.colorR) then MapNotesPOITooltipIcon:SetVertexColor(texture.colorR, texture.colorG, texture.colorB, texture.colorA); else MapNotesPOITooltipIcon:SetVertexColor(1, 1, 1, 1); end;
	-- set text
	MapNotesPOITooltipHeader:SetText(MapNotesSaved_NoteDB[noteID].title);
	-- set description
	MapNotesPOITooltipDescription:SetText(MapNotesSaved_NoteDB[noteID].description);
	local width = min(209, max(MapNotesPOITooltipHeader:GetStringWidth()+20, MapNotesPOITooltipDescription:GetStringWidth()));
	MapNotesPOITooltip:SetWidth(width+10);
	MapNotesPOITooltipBG:SetWidth(width);
	if (MapNotesPOITooltipDescription:GetHeight() > 1) then
		MapNotesPOITooltip:SetHeight(MapNotesPOITooltipDescription:GetHeight()+31);
	else
		MapNotesPOITooltip:SetHeight(25);
	end;
	return MapNotesPOITooltip;
end;